package com.nexgo.payment.trans.sale;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.nexgo.payment.constrant.CardMode;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.trans.AbsTransActivity;

/**
 * 消费界面
 * <p>
 * 用卡模式（普通消费：刷卡/挥卡/插卡、插卡消费：插卡、闪付凭密：挥卡）
 */
public class SaleActivity extends AbsTransActivity<SaleContract.Presenter> implements SaleContract.View {
    private static final String CARD_MODE = "card_mode";
    private static final String FORCE_PIN = "force_pin";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle bundle = getIntent().getExtras();
        CardMode cardMode = null;
        boolean forcePin = false;
        if (bundle != null) {
            cardMode = CardMode.values()[bundle.getInt(CARD_MODE, 0)];
            forcePin = bundle.getBoolean(FORCE_PIN, false);
        }
        new SalePresenter(this, Repository.getInstance(), cardMode, forcePin);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.start();
    }

    public static Intent newInstance(Context context) {
        return newInstance(context, null, false);
    }

    public static Intent newInstance(Context context, CardMode cardMode) {
        return newInstance(context, cardMode, false);
    }

    public static Intent newInstance(Context context, CardMode cardMode, boolean forcePin) {
        Intent intent = new Intent(context, SaleActivity.class);
        if (cardMode != null) {
            Bundle bundle = new Bundle();
            bundle.putInt(CARD_MODE, cardMode.ordinal());
            bundle.putBoolean(FORCE_PIN, forcePin);
            intent.putExtras(bundle);
        }
        return intent;
    }
}
